﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WMPLib;

namespace _10_01_13_mp3
{
    public partial class frmMain : Form
    {
        public WindowsMediaPlayer myPlayer;
        
        public frmMain()
        {
            InitializeComponent();
            InitializeMyStuff();
        }

        private void InitializeMyStuff()
        {
            //oletusarvo textboxille
            txtFileName.Text = @"d:\G2458\Testi.mp3";
            myPlayer = new WindowsMediaPlayer();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            //stop
            myPlayer.controls.stop();
            //UI:n viilaus
            btnPlay.Enabled = true;
            btnStop.Enabled = false;
        }

        private void btnPlay_Click(object sender, EventArgs e)
        {
            //soitto
            //WindowsMediaPlayer myPlayer;
            //myPlayer = new WindowsMediaPlayer();
            myPlayer.URL = txtFileName.Text;
            myPlayer.controls.play();
            //UI:n viilaus
            btnPlay.Enabled = false;
            btnStop.Enabled = true;
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            //avataan windowsin vakio open-dialogi, jotta käyttäjävä voi valita kappaleen
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtFileName.Text = ofd.FileName;
            }
        }
    }
}
